import {
	api
} from '@/common/utils/request.js';
import {
	toPageParam,
	toPageResult
} from '@/common/services/index.js'


/* 获取当前登录用户 */
export function currentUser() {
	return api({
		url: "/system/user/currentUser",
		hasLoading: false
	}).then(ret => {
		return ret.data;
	}).catch(e => {
	});
}


/* 获取账号列表 */
export function accountList(data) {
	return api({
		url: "/system/user/list",
		data: toPageParam(data),
		method: "post"
	}).then(ret => {
		return ret.data;
	}).catch(e => {
	});
}

/* 保存账号 */
export function accountSave(data) {
	/*
	{
	    "id": 520000200609086400,
	    "username": "tvueb",
	    "name": "吴超",
	    "mobile": "18184480262",
	    "email": "b.ogyg@smjeyvvw.no",
	    "roleId": 620000197607175400
	}
	 */
	return api({
		url: data.id && data.id > 0 ? `/system/user/edit/${data.id}` : "/system/user/add",
		data: data,
		method: "post"
	}).catch(e => {
	});
}

/* 删除账号 */
export function accountDelete(id) {
	return api({
		url: "/system/user/deleteById",
		data: {
			id
		},
		method: "get"
	}).catch(e => {
	});
}

/* 禁用账号 */
export function accountDisabled(id) {
	return api({
		url: "/system/user/toggleDisabled",
		data: {
			id
		},
		method: "get"
	}).catch(e => {
	});
}

/* 获取角色列表 */
export function roleList(data) {
	return api({
		url: "/system/role/list",
		data: toPageParam(data),
		method: "post"
	}).then(ret => {
		return ret.data;
	}).catch(e => {
	});
}

/* 保存角色 */
export function roleSave(data) {
	/*
	{
	    "id": 520000200609086400,
	    "roleNmae": "tvueb",
	    "remark": ""
	}
	 */
	return api({
		url: data.id && data.id > 0 ? `/system/role/edit/${data.id}` : "/system/role/add",
		data: data,
		method: "post"
	}).catch(e => {
	});
}

/* 删除角色 */
export function roleDelete(id) {
	return api({
		url: "/system/role/deleteById",
		data: {
			id
		},
		method: "get"
	}).catch(e => {
	});
}

/* 禁用角色 */
export function roleDisabled(id) {
	return api({
		url: "/system/role/toggleDisabled",
		data: {
			id
		},
		method: "get"
	}).catch(e => {
	});
}


/* 获取左侧菜单 */
export function leftMenus() {
	return api({
		url: "/system/menu/leftList",
		data: {}
	}).then(ret => {
		return ret.data;
	}).catch(e => {
	});
}


/* 获取菜单列表 */
export function menuList() {
	return api({
		url: "/system/menu/list",
		data: {}
	}).then(ret => {
		return toPageResult(ret.data);
	}).catch(e => {
	});
}

/* 保存菜单 */
export function menuSave(data) {
	/*
	{
	    "id": 320000199602248770,
	    "menuType": "0",
	    "menuNmae": "谭洋",
	    "parentPath": "zhinan|shejiyuanze|yizhi",
	    "icon": "home",
	    "sort": 1,
	    "remark": "irure amet",
	    "authCode": "73",
	    "path": "http://eiqj.bw/kjtjk"
	}
	 */
	return api({
		url: data.id && data.id > 0 ? `/system/menu/edit/${data.id}` : "/system/menu/add",
		data: data,
		method: "post"
	}).catch(e => {
	});
}

/* 删除菜单 */
export function menuDelete(id) {
	return api({
		url: "/system/menu/deleteById",
		data: {
			id
		},
		method: "get"
	}).catch(e => {
	});
}

/* 禁用菜单 */
export function menuDisabled(id) {
	return api({
		url: "/system/menu/toggleDisabled",
		data: {
			id
		},
		method: "get"
	});
}

/* 获取父级菜单下拉框 */
export function parentMenuDropDownList() {
	return api({
		url: "/system/menu/parentDropDownList",
		data: {},
		hasLoading: false
	}).then(ret => {
		return ret.data;
	});
}

/* 获取角色权限下拉框 */
export function roleMenuDropDownList() {
	return api({
		url: "/system/menu/roleDropDownList",
		data: {},
		hasLoading: false
	}).then(ret => {
		return ret.data;
	});
}


/* 获取角色权限下拉框 */
export function roleDropDownList() {
	return api({
		url: "/system/role/dropDownList",
		data: {},
		hasLoading: false
	}).then(ret => {
		return ret.data;
	});
}
